home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 5.4 KB | 210 lines | [TEXT/MMCC] |
- // ===========================================================================
- // SCModelProperty -- a model property that automatically handles undo
- // ===========================================================================
- // © 1994 James Kaput, SimCalc Project
-
- #include "SCModelProperty.h"
- #include "SCApp.h"
-
- SCModelProperty::SCModelProperty(DescType inPropertyID,
- LModelObject *inSuperModel) :
- LModelProperty(inPropertyID,nil) // nil prevents AddSubModel call
- {
- mSuperModel = inSuperModel;
- }
-
- SCModelProperty::~SCModelProperty()
- {
- mSuperModel = nil; // nil prevents RemoveSubModel call
- }
-
- void
- SCModelProperty::HandleSetData(const AppleEvent &inAppleEvent,
- AppleEvent &outAEReply)
- {
-
- SCApp::PostAction(new SCSetPropertyAction(GetSuperModel(),mPropertyID,inAppleEvent));
- }
-
- LDynamicArray *SCSetPropertyAction::sPropDescArray = nil;
-
- SCSetPropertyAction::SCSetPropertyAction(LModelObject *inObject,
- DescType inPropID,
- const AppleEvent &inAE)
- : LAction(200,3), mObject(inObject), mPropID(inPropID)
-
- {
- // get old data from object itself
- StAEDescriptor reply;
- mObject->GetAEProperty(mPropID, reply.mDesc, mOldData.mDesc);
-
- mNewData.GetParamDesc(inAE, keyAEData, typeWildCard);
-
- UAppleEventsMgr::CheckForMissedParams(inAE);
- }
-
- SCSetPropertyAction::~SCSetPropertyAction()
- {
- // descriptors automatically deleted!
- }
-
-
- void
- SCSetPropertyAction::RedoSelf()
- {
- StAEDescriptor result;
- mObject->SetAEProperty(mPropID,mNewData.mDesc,result.mDesc);
- }
-
- void
- SCSetPropertyAction::UndoSelf()
- {
- StAEDescriptor result;
- mObject->SetAEProperty(mPropID,mOldData.mDesc,result.mDesc);
- }
-
- void
- SCSetPropertyAction::GetDescriptor(Str63 outDescription)
- {
- DescribeProperty(mPropID,outDescription);
- }
-
-
- // this parses the 'aete' resource to build an array of associations
- // between 4-char property ids and Str255 property names
- void
- SCSetPropertyAction::InitPropDescriptors()
- {
- Handle terminology = Get1Resource('aete',0);
- LHandleStream stream(terminology);
- char buffer[20];
- Str255 pstring;
- short suiteCount, eventCount, classCount, compCount, enumCount,
- propCount, paramCount, tagCount, elemCount, formCount;
- SPropDesc prop;
-
- sPropDescArray = new LDynamicArray(sizeof(SPropDesc));
-
- stream.ReadData(buffer,6); // skip preliminaries
- stream.ReadData(&suiteCount,2); // count of suites
-
- while(suiteCount > 0) {
- stream.ReadPString(pstring); // suite name
- stream.ReadPString(pstring); // suite description
- ALIGN_WORD
- stream.ReadData(buffer,8); // skip suite stuff
-
- stream.ReadData(&eventCount,2); // count of events
- while (eventCount > 0) {
- stream.ReadPString(pstring); // event name
- stream.ReadPString(pstring); // event description
- ALIGN_WORD
- stream.ReadData(buffer,12); // skip event stuff
- stream.ReadPString(pstring); // reply description
- ALIGN_WORD
- stream.ReadData(buffer,6); // skip reply stuff
- stream.ReadPString(pstring); // direct object description
- ALIGN_WORD
- stream.ReadData(buffer,2); // skip direct object stuff
-
- stream.ReadData(¶mCount,2); // count of parameters
- while(paramCount > 0) {
- stream.ReadPString(pstring); // param name
- ALIGN_WORD
- stream.ReadData(buffer,8); // skip param stuff
- stream.ReadPString(pstring); // param description
- ALIGN_WORD
- stream.ReadData(buffer,2); // skip param stuff
- paramCount--;
- }
- eventCount--;
- }
-
- stream.ReadData(&classCount,2);
- while (classCount > 0) {
- stream.ReadPString(pstring); // class name
- ALIGN_WORD
- stream.ReadData(buffer,4); // skip class stuff
- stream.ReadPString(pstring); // class desc
- ALIGN_WORD
-
- stream.ReadData(&propCount,2); // count of properties
-
- while (propCount > 0) {
- stream.ReadPString(prop.name); // get prop name
- ALIGN_WORD
- stream.ReadData(&(prop.id),4); // get prop id
- stream.ReadData(buffer,4); // skip rest of prop
- stream.ReadPString(pstring); // get prop desc
- ALIGN_WORD
- stream.ReadData(buffer,2); // skip rest of prop
-
- sPropDescArray->InsertItemsAt(1,arrayIndex_Last,&prop);
-
- propCount--;
- }
-
- stream.ReadData(&elemCount,2); // count of elements
-
- while (elemCount > 0) {
- stream.ReadData(buffer,4); // skip elem id
- stream.ReadData(&formCount,2); // skip elem id
- stream.ReadData(buffer,formCount * 4); // skip forms
-
-
- elemCount--;
- }
-
-
- classCount--;
- }
-
- stream.ReadData(&compCount,2);
- while(compCount > 0) {
- stream.ReadPString(pstring); // comp name
- ALIGN_WORD
- stream.ReadData(buffer,4); // skip rest of prop
- stream.ReadPString(pstring); // comp desc
- ALIGN_WORD
- compCount--;
- }
-
- stream.ReadData(&enumCount,2);
- while(enumCount > 0) {
- stream.ReadData(buffer,4); // skip enumerator
- stream.ReadData(&tagCount,2);
- while (tagCount > 0) {
- stream.ReadPString(pstring); // tag name
- ALIGN_WORD
- stream.ReadData(buffer,4); // skip rest of tag
- stream.ReadPString(pstring); // tag desc
- ALIGN_WORD
- tagCount--;
- }
- enumCount--;
- }
- suiteCount--;
- }
- }
-
- // Jeremy 012 Mod
- Boolean
- SCSetPropertyAction::DescribeProperty(DescType inPropID, Str63 outDescriptor)
- {
- if (! sPropDescArray) InitPropDescriptors();
-
- SPropDesc prop;
- long i,count = sPropDescArray->GetCount();
-
- for(i = 1; i <= count; i++) {
- sPropDescArray->FetchItemAt(i,&prop);
- if (prop.id == inPropID) {
- CopyPStr(prop.name,outDescriptor);
- return true;
- }
- }
- return false;
- }
-
-
-